<script src="../../../http/index.js"></script>
<template>
  <div class="all">
    <div class="top">
       <header>
         <div class="div">
           <img src="../../../assets/返回.png" @click="back()" alt="">
           <span class="solid" @click="back()">返回</span>
         </div>
         <div class="div">
           <span>信息筛查</span>
         </div>
         <div class="div">
           <button class="screenBtn" @click="selectShow = true">
             <img src="../../../assets/筛选黑.png" alt="">筛选
           </button>
<!--           <span class="solid"></span>-->
         </div>
       </header>
      <div class="screen" @click="riqiShow=true">
<!--        <span style="display: flex;align-items: center;"-->
<!--              @click="riqiShow=true">选择日期：{{startTime}} 至 {{endTime}}-->
<!--          <img style="width: 10px;height: 5px;margin-left: 5px" src="../../../assets/imageZhaoPin/下拉@2x.png" alt=""></span>-->

        <span style="display: flex;align-items: center" >选择日期</span>
        <span>
          <span class="inputBorder"> {{startTime}}</span>
          <span style="margin: 0 10px">至</span>
          <span class="inputBorder"> {{endTime}}</span>
        </span>

      </div>
      <van-overlay :lock-scroll="false"  :show="selectShow" @click="selectShow = false">
        <div class="popSelect" @click.stop="">
          <div v-for="(item, index) in menuList" :key="index">
            <div class="popTitle" v-if="item.dict_type === 'health_info'">{{item.dict_name}}</div>
            <div class="popContent" v-if="item.dict_type === 'health_info'">
              <button class="selectBtn" :class="[childenItem.select == true ? 'select' : '']" @click.stop="selectBtn(item, childenItem)"
                      v-for="(childenItem, childenIndex) in item.oauths"
                      :key="childenIndex">{{childenItem.title}}</button>
            </div>
          </div>
          <div class="popBottom">
            <button class="reset" @click.stop="reset()">重置</button>
            <button class="queren" @click.stop="determine()">确认</button>
          </div>
        </div>
      </van-overlay>
    </div>
    <div class="content" v-for="(item, index) in list" :key="index" v-if="list.length > 0">
      <div class="titleDate">
        <img src="../../../assets/蓝圆.png" alt="">
        <span style="margin-left: 8px">{{item.date}}</span>
<!--        <span style="margin-left: 8px">{{index}}</span>-->
      </div>
      <div class="box">
        <ul @click="clickRun(childenItem)"
            v-for="(childenItem, childenIndex) in item.data"
            :key="childenIndex"
            v-if="Number(childenItem.count) > 0"
        >
          <li style="
color: #333333;">
            <span>{{childenItem.title}}</span>
          </li>
          <li style="
color: #666666;">
            <span style="margin-right: 5px" v-show="Number(childenItem.count) > 0">{{childenItem.count}}条记录</span>
            <img src="../../../assets/更多灰@2x.png" alt="">
          </li>
        </ul>
      </div>
    </div>
    <div class="loading" v-show="isloading">
      <van-loading  size="24px" type="spinner" color="#1989fa">加载中...</van-loading>
    </div>
    <van-empty
      v-if="list.length <= 0 && isloading === false"
      style="width: 100%;height: 60%"
      class="custom-image"
      :image="require('../../../assets/空两本书.png')"
      description="暂无健康记录"
    />
    <van-calendar v-model="riqiShow"
                  :min-date="minDate"
                  :max-date="maxDate"
                  :value="selectDate"
                  :show-confirm="false"
                  :round="false"
                  type="range"
                  color="#1da4f2"
                  @confirm="onConfirm"
                  position="right" />
<!--    <van-popup  position="top" v-model="selectShow" :style="{ top: '100px', height: '60%' }" />-->
  </div>
</template>

<script>
import $ from 'jquery'
export default {
  name: 'HealthList',
  data () {
    return {
      data_user_id: this.$route.query.data_user_id,
      startTime: '',
      endTime: '',
      list: [],
      minDate: new Date(2000, 0, 1),
      maxDate: new Date(),
      selectDate: '',
      riqiShow: false,
      menuList: [],
      selectShow: false,
      ids: [],
      isloading: false
    }
  },
  mounted () {
    if (sessionStorage.getItem('HealthList') !== null) {
      let data = JSON.parse(sessionStorage.getItem('HealthList'))
      this.startTime = data.startTime
      this.endTime = data.endTime
      this.menuList = data.menuList
    } else {
      this.startTime = this.formatDate(new Date().setDate((new Date().getDate() - 7)))
      this.endTime = this.formatDate(new Date())
      this.getMenu()
    }
    this.getData()
  },
  methods: {
    // 筛选重置按钮
    reset () {
      this.ids = []
      this.getMenu()
      // this.selectShow = true
    },
    // 筛选确认按钮
    determine () {
      this.getData()
      this.selectShow = false
    },
    // 点击选中筛选框
    selectBtn (item, childenItem) {
      if (childenItem.select !== undefined) {
        childenItem.select = !childenItem.select
      } else {
        this.$set(childenItem, 'select', true)
      }
      // this.ids.push(childenItem.id)
      for (let i in this.ids) {
        if (this.ids[i] == childenItem.id) {
          this.ids.splice(i, 1)
          return false
        }
      }
      this.ids.push(childenItem.id)
    },
    // 获取菜单
    getMenu () {
      this.$http.listHealthInfo({data_user_id: this.data_user_id})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            this.menuList = res.data.data
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 点击选择日期
    onConfirm (date) {
      const [start, end] = date
      this.riqiShow = false
      // this.selectDate = `${this.formatDate(start)} - ${this.formatDate(end)}`
      this.startTime = this.formatDate(start)
      this.endTime = this.formatDate(end)
      this.getData()
    },
    // 点击某条数据跳转
    clickRun (childenItem) {
      var query = JSON.parse(childenItem.param)
      query.isEdit = 0
      query.time = childenItem.time
        this.$router.push({path: childenItem.url, query: query})
    },
    getData () {
      this.isloading = true
      var idList
      if (this.ids.length <= 0) {
        idList = ''
      } else {
        idList = this.ids.toString()
      }
      this.$http.healthShaiXuan({ids: idList, data_user_id: this.data_user_id, sTime: this.startTime, eTime: this.endTime})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            this.list = []
            for (var i in res.data.data) {
              var obj = {
                date: i,
                data: res.data.data[i]
              }
              this.list.push(obj)
            }
            this.isloading = false
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    formatDate (date) {
      var date = new Date(date)
      var YY = date.getFullYear() + '-'
      var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
      var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
      //
      // var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
      //
      // var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
      //
      // var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds())

      return YY + MM + DD
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    }
  },
  destroyed() {
    let obj = {
      menuList: this.menuList,
      startTime: this.startTime,
      endTime: this.endTime
    }
    sessionStorage.setItem('HealthList', JSON.stringify(obj))
  }
}
</script>

<style scoped>
  /*加载*/
  .loading {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center !important;
    justify-content: center !important;
  }
  .all{
    width: 100%;
    height: 100%;
    background: #FAF9FE;
    overflow: auto;
  }
  .top{
    position: sticky;
    top: 0;
    z-index: 9999;
    background: white;
  }
  header{
   width: 100%;
   height: 44px;
   display: flex;
   align-items: center;
   border-bottom: 1px solid #E5E5E5;
  }
  .div{
   width: 33%;
   height: 100%;
   display: flex;
   align-items: center;
   font-family: "PingFang SC";
   font-size: 15px;
   font-weight: bold;
  }
  .div img{
   margin-right: 5px;
  }
  .div:nth-child(1) img{
   height: 13px;
   width: 7px;
   margin-left: 15px;
  }
  .div:nth-child(3) img{
   margin-right: 5px;
  }
  .div:nth-child(3) span{
   margin-right: 15px;
  }
  .div:nth-child(2){
   justify-content: center;
  }
  .div:nth-child(3){
   justify-content: flex-end;
  }
  .solid{
   color: #1DA4F2;
  }
  .screen{
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    box-sizing: border-box;
  }
  .screen span{
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .inputBorder{
    width: 100px;
    height: 29px;
    border: 1px solid #1DA4F2;
    border-radius: 4px;
    text-align: center;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .popSelect{
    width: 100%;
    height: 86%;
    position: fixed;
    top:44px;
    background: white;
    overflow: auto;
  }
  .popTitle{
    width: 100%;
    height: 44px;
    background: #FFFFFF;
    box-shadow: 0px 1px 0px 0px #E5E5E5;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #1DA4F2;
    display: flex;
    align-items: center;
    padding: 0 10px;
    box-sizing: border-box;
  }
  .popContent{}
  .selectBtn{
    width: 100px;
    height: 29px;
    border-radius: 5px;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 500;
    border: none;
    margin: 8px;
    background: #f3f3f3;
  }
  .popBottom{
    width: 100%;
    height: 44px;
    background: #FFFFFF;
    border-radius: 0px 0px 20px 20px;
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: bold;
  }
  .popBottom button{
    width: 90px;
    height: 29px;
    border: 1px solid #1DA4F2;
    border-radius: 10px;
  }
  .reset {
    background: #FFFFFF;
    color: #1DA4F2;
  }
  .queren {
    margin-left: 30px;
    color: white;
    background: #1DA4F2;
  }
  .select{
    color: #fff;
    background: #1DA4F2;
  }
  .screenBtn{
    width: 60px;
    height: 25px;
    border: 1px solid #1DA4F2;
    border-radius: 5px;
    background: transparent;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #333333;
  }
  .screenBtn img{
    width: 10px;
    height: 10px;
    margin-right: 3px;
  }
  /deep/ .van-overlay{
    top: 44px;
  }
  .content{
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
  }
  .content:last-child{
    margin-bottom: 50px;
  }
  .box{
    border-left: 2px solid rgba(29, 164, 242, 0.2);
    width: 92%;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    flex-direction: column;
  }
  .titleDate img{
    width: 12px;
    height: 12px;
  }
  .titleDate {
    width: 95%;
    height: 44px;
    display: flex;
    align-items: center;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #333333;
  }
  .box ul {
    width: 95%;
    height: 35px;
    box-shadow: 0px 2px 6px 0px rgba(190, 192, 194, 0.2);
    border-radius: 10px;
    background: white;
    padding: 0 8px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-family: PingFang SC;
    font-weight: 500;
    margin-bottom: 5px;
  }
  .box ul li{
    display: flex;
    align-items: center;
  }
  .box ul li img{
    width: 7px;
    height: 13px;
  }
</style>
